
public class e027 {
    public static void main(String[] args) {
        long sTime = System.currentTimeMillis();
        int biggest = 0;
        int bigA = 0;
        int bigB = 0;
        for (int a = -999; a < 1000; a += 2) {
            for (int b = 1; b < 1000; b += 2) {
                if (isPrime(b)) {
                    int n = numPrimes(a, b);
                    if (n > biggest) {
                        biggest = n;
                        bigA = a;
                        bigB = b;
                    }
                }
            }
        }
        System.out.println(bigA * bigB);
        long fTime = System.currentTimeMillis();
        System.out.println("Time: " + (fTime - sTime) + "ms");
    }

    static int numPrimes(int a, int b) {
        int n = 0;
        while (isPrime(Math.abs(n*n + a*n + b))) {
            n++;
        }
        return n;
    }

    static boolean isPrime(int n) {
        for (int i = 2; i <= Math.sqrt((double)n); i++) {
            if (n % i == 0) {
                return false;
            }
        }
        return true;
    }
}
